//
//  Cookie.swift
//  Employee
//
//  Created by swordjoy on 2017/5/9.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation

let Cookie_Key = "Cookie_Key"

struct Cookie {

  static func clearAll() {
    let clearDic = NSDictionary()
    clearDic.write(to: Cookie.cacheFileName, atomically: true)
  }
  
  static var cookie: String {
    return (Cookie.cookieInfoDic?.object(forKey: Cookie_Key) as? String) ?? ""
  }
  
  static func cacheCookie(cookie: String) {
    
    let cookieDic = NSMutableDictionary()
    cookieDic.setObject(cookie, forKey: Cookie_Key as NSString)
    cookieDic.write(to: Cookie.cacheFileName, atomically: true)
    
  }
  
  static var cacheFileName: URL {
    
    return SJApp.cachesURL.appendingPathComponent("Cookie.plist")
    
  }
  
  static var cookieInfoDic: NSMutableDictionary? {
    
    return NSMutableDictionary(contentsOf: Cookie.cacheFileName)
    
  }
  
}
